<?exit?>
<!--{template 'templates/site/default/header.html.php', 1}-->
<div class="wrap cat mbm cl" style="height:600px;">
	<div class="cat_c">
		<div id="category">
			<ul>
			<!--{eval $cat_count = 0;}-->
			<!--{loop $_G['categorylist'] $cat}-->
				<!--{if $cat[upid] == 0}-->
				<!--{eval $cat_count ++;}-->
				<li id="cat_{$cat['catid']}"{if $cat_count > 8} style="display:none;"{/if}>
					<h3><b>&gt;</b><a href="map.php">{$cat['name']}</a></h3>
					<!--{if $cat['havechild']}-->
						<!--{eval $subcatids = explode(', ', $cat['subcatid']); }-->
						<div class="category_c" id="cat_{$cat['catid']}_menu">
							<!--{loop $subcatids $c_cat}-->
							<!--{if $_G['categorylist'][$c_cat]['upid'] != 0 && $_G['categorylist'][$c_cat]['catid'] > 0}-->
							<a href="#" onclick="changcatid({$_G['categorylist'][$c_cat]['catid']})">$_G['categorylist'][$c_cat]['name']</a>
							<!--{/if}-->
							<!--{/loop}-->
						</div>
					<!--{/if}-->
				</li>
				<!--{/if}-->
				<!--{/loop}-->
			</ul>
			<!--{if $cat_count > 8}-->
			<a id="more_cat" href="javascript:;" title="{$lang['more_shop']}">{$lang['more_shop']}</a>
			<!--{/if}-->
		</div>
		<!--{ad/modulebanner/mtm/6}-->
	</div>

	<div id="focus" style="border:1px solid #FF944D; width:770px;">
		<div class="content">
		
			<div>
				<input type="hidden" id="inputmap" value="">
				<input type="hidden" id="shopid" value="$shopid">
			</div>
				<div style="width: 770px; height: 550px;" class="main_map" id="mapObj">
			</div>
		</div>
	</div>
</div>
<script charset="utf-8" type="text/javascript" src="static/js/index.js"></script>
<script src="http://ditu.google.cn/maps/api/js?sensor=false&language=zh-CN" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">

	var map;
	var marker;
	var infowindow;
	var draggable = 'true';
	var markersArray = [];
	function initialize() {
		var latlng;
		var mapapimark = {$defaultshopmap};
		var local = "$_SC[local]";

		//检查是否设置中心地点
		if(!local) {
			var defaultmapaction = true;
			latlng = new google.maps.LatLng(39.917,116.397);
		} else {
			var geoaction = true;
		}
		
		var myOptions = {
			zoom: 12,
			center: latlng,
			navigationControl: true,
			mapTypeControl: true,
			scaleControl: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};

		//初始化地图并设置中心
		map = new google.maps.Map(document.getElementById("mapObj"), myOptions);
		if(geoaction) {
			var geocoder = new google.maps.Geocoder();
			if(geocoder) {
				geocoder.geocode({'address': local}, function(results, status) {
					if(status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
					} else {
						alert("{$lang['shopmap_mark_error']}");
					}
				});
			}
		}
	
	}
	//打开时载入默认店铺
	function loadshop(markarr){
		var tmparr = [];
		shoptitle = '{$shoptitle}';
		newshoptitle = shoptitle.split("^");
		tmparr = markarr.split("^");
		for(var a = 0;a < tmparr.length;a++) {
			tmparr_2 = tmparr[a].split(",");
			tmpmark =  new google.maps.LatLng(tmparr_2[0], tmparr_2[1]);
			var marker =  new google.maps.Marker({
      							position: tmpmark,
     							map: map
			});
			markersArray[a] = marker;
			marker.setTitle(newshoptitle[a]);
			attachSecretMessage(marker, a, "{$info_shop}");
			tmparr_2 = '';
		}
		//showOverlays(markersArray);
	}

	//点击分类连接触发事件
	function changcatid(catid){
		var newmark;
		var tmp = [];

		if (markersArray) {
    			for (k in markersArray) {
      				markersArray[k].setMap(null);
    			}
   			 markersArray.length = 0;
		}

		
		$.get("map.php?catid="+catid, function(data){
			if(data != 0){
				newdata = data.split("|");
				newshoptitle = newdata[2].split("^")
				newmark = newdata[1].split("^");
				for(var j = 0; j < newmark.length;j++){
					tmp = newmark[j].split(",");
					mymark = new google.maps.LatLng(tmp[0], tmp[1]);
					var marker =  new google.maps.Marker({
      							position: mymark,
     							map: map
					}); 
					markersArray[j] = marker;
					marker.setTitle(newshoptitle[j]);
					attachSecretMessage(marker, j, newdata[0]);
					map.setCenter(mymark);
					tmp = '';
				}
			}else{
				alert("{$lang['no_shop']}");
				loadshop('{$str_shop}');
			}
		});	
	}

	function attachSecretMessage(marker, i, data){
		var contentstr = data;
		var contentarr = contentstr.split("^");
		var infowindow = new google.maps.InfoWindow({ 
			content: contentarr[i],
       			size: new google.maps.Size(50,50)
		});
  		google.maps.event.addListener(marker, 'click', function() {
    			infowindow.open(map,marker);
  		});	
		google.maps.event.addListener(map, 'click', function() {
    			infowindow.close(map);
  		})
		google.maps.event.addListener(map, "dragstart", function(event) {
			infowindow.close(map);
		});
	}

	function showOverlays(markersArray) {
  		if (markersArray) {
			for (i in markersArray) {
      				markersArray[i].setMap(map);
   		 	}
 		}
		adlistener();
	}
initialize();	
loadshop('{$str_shop}');
</script>
<!--{ad/horbanner/wrap mbm/1}-->
<!--{template 'templates/site/default/footer.html.php', 1}-->


